#include <vector>
class NumMatrix {
public:
    std::vector<std::vector<int>> res;
    NumMatrix(std::vector<std::vector<int>>& matrix) {
        int n = matrix.size();
        int m = matrix[0].size();
         res.resize(n+1,std::vector<int>(m+1,0));
        for (int i = 1; i <=n; i++)
        {
            for (int j = 1; j <=m; j++)
            {
                res[i][j] = matrix[i-1][j-1] ;
            }
        }
        for (int i=1;i<=n;i++)
        {
            for (int j=1;j<=m;j++)
            {
                res[i][j] +=res[i-1][j]+res[i][j-1]-res[i-1][j-1];
            }
        }
    }
    
    int sumRegion(int row1, int col1, int row2, int col2) {
        row2++;
        col2++;
        return res[row2][col2]-res[row2][col1]-res[row1][col2]+res[row1][col1];
    }
};

